#include "Parser.h"

bool Parser::match(char c)
{
  if(c == '+' || c == '-' || c == '>' || c == '<' ||
     c == ',' || c == '.' || c == '[' || c == ']')
    return true;
  return false;
}

string Parser::filter(string in)
{
  string out = "";
  for(int i = 0; i < in.length(); i++)
    if(match(in[i]))
      out += in[i];
  return out;
}

Parser::Parser(int argc, char ** argv)
{
  for(int i = 1; i < argc; i++)
    {
      string x = argv[i];
      if(x=="-n" || x=="-N")
	{
	  Main::numericMode = true;
	  cin.setf(ios::skipws);
	  continue;
	}
      if(match(x[0]))
	{
	  contents.push_front(filter(x));
	  continue;
	}
      try
	{
	  File file(x);
	  contents.push_front(filter(file.toString()));
	}
      catch(Exception * e)
	{
	  cout << e->toString();
	  delete e;
	}
    }
}

bool Parser::peek()
{
  return !contents.empty();
}

string Parser::pop()
{
  string content = contents.back();
  contents.pop_back();
  return content;  
}
